﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Web.UI.WebControls;
using Axe.Extensions;

namespace Axe.Web.Controls
{
    public class ToggleWikiAuthorMode : Button
    {
        [DefaultValue("Leave edit mode...")]
        public string LeaveAuthoringModeText
        {
            get { return ViewState.Get("LeaveAuthoringModeText", "Leave edit mode..."); }
            set { ViewState["LeaveAuthoringModeText"] = value; }
        }

        [DefaultValue("Enter edit mode...")]
        public string EnterAuthoringModeText
        {
            get { return ViewState.Get("EnterAuthoringModeText", "Enter edit mode..."); }
            set { ViewState["EnterAuthoringModeText"] = value; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new string Text
        {
            get 
            {
                return WikiContentControl.IsInEditMode ? LeaveAuthoringModeText : EnterAuthoringModeText;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.Text = this.Text;
            base.OnPreRender(e);
        }

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            if (WikiContentControl.IsInEditMode)
                WikiContentControl.LeaveEditWikiMode();
            else
                WikiContentControl.EnterEditWikiMode();
        }
    }
}
